package com.bulls.demo.hrmsdemo.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.bulls.demo.hrmsdemo.db.User;



public class LoginDAOImpl implements LoginDAO{

	public User fetchUser(String username,EntityManager entityManager) {
		
		User user = null;
		try{
		System.out.println("uerName------>"+entityManager);
		if(username !=null){
		Query query =entityManager.createNamedQuery("fetchUserByName");
		System.out.println("query"+query);
		query.setParameter("userName", username);
		System.out.println("uerName------>"+username);
		List<User> usersList = query.getResultList();
		System.out.println("lenghth---"+usersList);
		if(usersList.size()>0){
			user = (User) usersList.get(0);
		}
		}
		}catch(Exception e){
			e.printStackTrace();
		}
		return user;
	}

}
